package org.dinnermate.menu;

import java.sql.SQLException;

import net.java.ao.DBParam;

import org.dinnermate.db.AbstractImplementation;
import org.dinnermate.db.DBManager;

public class MenuImpl extends AbstractImplementation<Menu>
{
	public MenuImpl( Menu menu )
	{
		super(menu);
	}
	
	public String toString()
	{
		return ao.getName();
	}

	public MenuToItem[] setMenuItems( MenuItem[] menuItems ) throws SQLException
	{
		this.deleteMaps(MenuToItem.class);

		MenuToItem[] maps = new MenuToItem[menuItems.length];
		int x = 0;
		for (MenuItem item : menuItems)
		{
			maps[x++] = addMenuItem(item);
		}
		
		return maps;
	}

	public MenuToItem addMenuItem( MenuItem menuItem ) throws SQLException
	{
		DBParam menu = new DBParam("menuID", ao);
		DBParam mi = new DBParam("menuItemID", menuItem);
		DBParam[] params = { menu, mi };
		return DBManager.getEntityManager().create(MenuToItem.class, params);
	}
}
